<?php
/* OpenBIBLIO -- A library administration web interface
 * Copyright (C) 2011-2012 Laurent Luyssen   <big.lol13@gmail.com>
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
 */
include_once "../../includes/db.inc";
// Check if user is logged on
session_start();
if (!isset($_SESSION['login']) || empty($_SESSION['login'])) {
	header("HTTP/1.1 401 Unauthorized");
	exit();
}

// Check request parameters
if (isset($_GET['eleve_id']) && !empty($_GET['eleve_id']))
	$eleve_id = $_GET['eleve_id'];
else {
	header("HTTP/1.1 400 Bad request");
	exit();
}
	
if (isset($_GET['livre_id']) && !empty($_GET['livre_id']))
	$livre_id = $_GET['livre_id'];
else {
	header("HTTP/1.1 400 Bad request");
	exit();
}
	
if (isset($_GET['lu']) && !empty($_GET['lu']))
	$lu = $_GET['lu'];
else {
	header("HTTP/1.1 400 Bad request");
	exit();
}

if (strcasecmp($lu, 'true') ==  0)
	$sql = "REPLACE INTO lus (livre_id, eleve_id, date_lu) values ($livre_id, $eleve_id, NOW())";
else
	$sql = "DELETE FROM lus WHERE livre_id=$livre_id AND eleve_id=$eleve_id";

biblio_db_query($sql);
?>
